<?php
/**
-------------------------
GNU GPL COPYRIGHT NOTICES
-------------------------
This file is part of FlexicaCMS.

FlexicaCMS is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

FlexicaCMS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with FlexicaCMS.  If not, see <http://www.gnu.org/licenses/>.*/

/**
 * $Id$
 *
 * @author FlexicaCMS team <contact@flexicacms.com>
 * @link http://www.flexicacms.com/
 * @copyright Copyright &copy; 2009-2010 Gia Han Online Solutions Ltd.
 * @license http://www.flexicacms.com/license.html
 */

////Begin - Coding constants ////
//CRUD Actions
define('ACTION_CREATE',                     'create');
define('ACTION_EDIT',                       'edit');
define('ACTION_DELETE',                     'delete');
define('ACTION_DELETE_ALL',                 'deleteall');
//Errors
define('ERROR_INVALID_DATA',                'data error');
define('ERROR_UNAUTHORIZED',                'auth error');
define('ERROR_HANDLING_DB',                 'db error');
define('ERROR_HANDLING_FILE',               'file error');
define('ERROR_VIOLATING_BUSINESS_RULES',    'business error');
////End   - Coding constants ////

class FlexiCore extends CApplicationComponent
{
    public $config = 'main';
    
    public $FrontendRenderer = 'CPradoViewRenderer';
    
    public $AssetUrl;
    public $AssetFolder;
    
    public function init() {
        parent::init();
        //Load config file
        $config = require(dirname(__FILE__).'/config/'.$this->config.'.php');
        //Import core files
        foreach($config['autoload'] as $path)
            Yii::import($path,true);
        foreach($config['imports'] as $path)
            Yii::import($path);
        
        //If this is a console app, don't publish assets folder
        if(Yii::app() instanceof CConsoleApplication){
             return;
         }
            
        if (isset($_GET['r']) && Yii::app()->urlManager->urlFormat == 'path')
            Yii::app()->urlManager->urlFormat = 'get';
        //Publish assets
        $asset = dirname(__FILE__).'/../assets';
        $this->AssetUrl = Yii::app()->assetManager->publish($asset, false, -1, YII_DEBUG);
        $this->AssetFolder = Yii::app()->assetManager->getPublishedPath($asset);
    }
}
?>